#!/usr/bin/python
#coding:utf8
from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText
import time
i = 1
def SendEamil():
	mail_info = {
		"from": "13924594600@139.com",
		"to": "13924594600@139.com",
		"hostname": "smtp.139.com",
		"username": "13924594600@139.com",
		"password": "abc123abc",
		"mail_subject": "阿里云发布代码故障",
		"mail_text": "阿里云发布代码故障 %s" % i,
		"mail_encoding": "utf-8"
	}
	#这里使用SMTP_SSL就是默认使用465端口
	smtp = SMTP_SSL(mail_info["hostname"], 465)
# debug模式
#	smtp.set_debuglevel(1)

	smtp.ehlo(mail_info["hostname"])
	smtp.login(mail_info["username"], mail_info["password"])

	msg = MIMEText(mail_info["mail_text"], "plain", mail_info["mail_encoding"])
	msg["Subject"] = Header(mail_info["mail_subject"], mail_info["mail_encoding"])
	msg["from"] = mail_info["from"]
	msg["to"] = mail_info["to"]

	smtp.sendmail(mail_info["from"], mail_info["to"], msg.as_string())

	smtp.quit()


i = 0
while True:
    try:
        SendEamil()
    except:
        print "Error: 无法发送邮件"
    time.sleep(30)
    i += 1
    if i == 10:
        break
